package com.mall.untils;

import redis.clients.jedis.Jedis;

public class RedisUtil {
	private static String host = "123.56.162.14";//控制台显示访问地址
	private static int port = 6379;
	private static String passwd="5c186119a13347d7:Redis123redis";
	private static int db=1;
	/**
	 * 设置
	 * @param key
	 * @param object
	 */
	public static void setRedisObject(String key,Object object){
        try {
            Jedis jedis = new Jedis(host, port);
            //鉴权信息由用户名:密码拼接而成
            jedis.auth(passwd);//instance_id:password
            //select db默认为0
            jedis.select(db);
            //set一个key
            jedis.set(String.valueOf(key), String.valueOf(object));
            jedis.quit();
            jedis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	/**
	 * 获取
	 * @param key
	 * @return
	 */
	public static String getRedisObject(String key){
        try {
        	Jedis jedis = new Jedis(host, port);
            //鉴权信息由用户名:密码拼接而成
            jedis.auth(passwd);//instance_id:password
            //select db默认为0
            jedis.select(db);
            //set一个key
            String getvalue = jedis.get(key);
            
            jedis.quit();
            jedis.close();
            return getvalue;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
	}
	/**
	 * 删除
	 * @param key
	 */
	public static void delRedisKey(String key){
        try {
        	
        	Jedis jedis = new Jedis(host, port);
            //鉴权信息由用户名:密码拼接而成
            jedis.auth(passwd);//instance_id:password
            //select db默认为0
            jedis.select(db);
            //set一个key
            jedis.del(key);
            jedis.quit();
            jedis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	public static void main(String[] args) {
		System.out.println(getRedisObject("201605316077820account"));
	}
}
